package com.skwen.delivery.superdelivery;

import android.content.Context;

import com.mob.MobApplication;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;


/**
 * Created by yundantian on 2017/8/28.
 */

public class App extends MobApplication {


    private static Context mContext;
    private static TencentLocation mLastLocation;
    private int mLastError;
    private static boolean mStarted;
    private static TencentLocationManager tencentLocationManager;


    @Override
    public void onCreate() {
        super.onCreate();
        this.mContext = this;
        tencentLocationManager = TencentLocationManager.getInstance(mContext);
        start();
    }




    public static void start() {
        if (!mStarted) {
            mStarted = true;
            TencentLocationRequest request = TencentLocationRequest.create()
                    .setInterval(5000)
                    .setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_POI);
            int error = tencentLocationManager
                    .requestLocationUpdates(request,tencentLocationListener);
        }
    }

    public static void stop() {
        if (mStarted) {
            tencentLocationManager.removeUpdates(tencentLocationListener);
            mStarted = false;
        }
    }

    public static TencentLocation getLocation(){
//        if (mLastLocation != null){
//            return mLastLocation;
//        } else {
//
//        }
        start();
        return mLastLocation;
    }




    static TencentLocationListener tencentLocationListener = new TencentLocationListener() {
        @Override
        public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
            mLastLocation = tencentLocation;
            stop();
        }

        @Override
        public void onStatusUpdate(String s, int i, String s1) {

        }
    };

}
